package com.aspose.cells;

import java.util.ArrayList;

class zcr {
   static void a(zuk var0) {
      byte[] var1 = var0.f();
      if (var1 != null && var1.length >= 4) {
         if (var1.length == 4) {
            var0.a(new byte[2]);
         } else {
            byte[] var2 = new byte[var1.length - 2];
            System.arraycopy(var1, 0, var2, 0, 2);
            System.arraycopy(var1, 4, var2, 2, var1.length - 4);
            var0.a(var2);
         }
      }
   }

   public static byte[] a(byte[] var0, int var1) {
      int var2 = var0.length;
      int var3 = var2;
      int var4 = var2;
      boolean var5 = false;
      zct var6 = null;
      int var7 = var1;
      int var8 = 0;
      if (var1 == -1) {
         var7 = 4;
         var2 = com.aspose.cells.b.a.zc.a(var0, 0);
         var3 = var7 + var2;
         if (var3 < var0.length) {
            var8 = com.aspose.cells.b.a.zc.a(var0, var3);
            var4 = var3 + 4;
         }

         var5 = true;
         var6 = new zct(var2 + 4);
      } else {
         var6 = new zct(var0.length);
      }

      if (var4 >= var0.length) {
         var8 = 0;
      }

      zct var9 = null;
      if (var8 != 0) {
         var9 = new zct(var8);
         a(var0, var4, var8, var9);
      }

      ArrayList var10 = new ArrayList();
      a(var0, var7, var3, var6, var10);
      int var11;
      if (var10.size() != 0) {
         for(var11 = 0; var11 < var10.size(); ++var11) {
            int[] var12 = (int[])((int[])var10.get(var11));
            var6.a(var12[2], com.aspose.cells.b.a.zc.a(var12[1] - var12[0] - var12[3]), 0, 2);
         }
      }

      var11 = var6.b();
      if (var11 > 65535) {
         return new byte[]{2, 0, 28, 42};
      } else {
         byte[] var14;
         if (var5) {
            var11 += var8 != 0 ? var9.b() : 0;
            var14 = new byte[var11 + 2];
            System.arraycopy(com.aspose.cells.b.a.zc.a(var6.b()), 0, var14, 0, 2);
            var6.a(var14, 2);
            if (var8 != 0) {
               int var13 = var6.b() + 2;
               var9.a(var14, var13);
            }

            return var14;
         } else {
            var14 = new byte[var11];
            var6.a(var14, 0);
            return var14;
         }
      }
   }

   private static boolean a(int var0, int var1, int var2, int var3) {
      if (var0 == 0 && var2 == 1048575) {
         return var1 > 255 || var3 > 255;
      } else if (var1 == 0 && var3 == 16383) {
         return var0 > 65535 || var2 > 65535;
      } else {
         return var0 <= 65535 && var2 <= 65535 && var1 <= 255 && var3 <= 255;
      }
   }

   private static void a(ArrayList var0, int var1, int var2, zct var3) {
      int var4 = var1;
      if (var0.size() != 0) {
         for(int var5 = 0; var5 < var0.size(); ++var5) {
            int[] var6 = (int[])((int[])var0.get(var5));
            if (var4 >= var6[0]) {
               if (var4 >= var6[1]) {
                  if (var6[3] != 0) {
                     var3.a(var6[2], com.aspose.cells.b.a.zc.a(var6[1] - var6[0] - var6[3]), 0, 2);
                  }

                  var0.remove(var5--);
               } else {
                  var6[3] += var2;
               }
            }
         }

      }
   }

   private static int a(byte[] var0, int var1, int var2, zct var3, ArrayList var4) {
      int var5 = var1;
      int var6 = var2;
      int[] var11 = new int[4];

      while(true) {
         while(var5 < var6) {
            int var7;
            int var8;
            int var9;
            int var10;
            int var15;
            int var16;
            switch(var0[var5]) {
            case 1:
            case 2:
               var7 = com.aspose.cells.b.a.zc.a(var0, var5 + 1);
               var9 = zcew.a(var0, var5 + 5);
               if (var7 <= 65535 && var9 <= 255) {
                  var3.a(var0, var5, 3);
                  var3.a(var0, var5 + 5, 2);
               } else {
                  var3.a((byte)42);
                  var3.a((int)4);
               }

               var5 += 7;
               break;
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
            case 17:
            case 18:
            case 19:
            case 20:
            case 21:
            case 22:
               var3.a(var0[var5]);
               ++var5;
               break;
            case 23:
               int var12 = com.aspose.cells.b.a.zc.e(var0, var5 + 1) & '\uffff';
               var3.a(var0[var5]);
               var3.a(var0[var5 + 1]);
               var3.a((byte)1);
               var3.a(var0, var5 + 3, var12 * 2);
               var5 += var12 * 2 + 3 & '\uffff';
               break;
            case 24:
               if (var0[var5 + 1] == 25) {
                  var3.a(var0, var5, 14);
                  var5 += 14;
               } else if (var0[var5 + 1] == 29) {
                  var3.a(var0, var5, 6);
                  var5 += 6;
               } else {
                  var3.a(var0[var5]);
                  ++var5;
               }
               break;
            case 25:
               byte var13 = 4;
               boolean var14 = false;
               int var20;
               switch(var0[var5 + 1]) {
               case 2:
               case 8:
                  var3.a(var0, var5, var13);
                  var20 = com.aspose.cells.b.a.zc.e(var0, var5 + 2) & '\uffff';
                  var5 += 4;
                  var11 = new int[]{var5, var5 + var20, var3.b() - 2, 0};
                  com.aspose.cells.b.a.a.ze.a(var4, (Object)var11);
                  continue;
               case 4:
                  var15 = com.aspose.cells.b.a.zc.e(var0, var5 + 4);
                  int var19 = (var15 & '\uffff') + 4;
                  var3.a(var0, var5, var19);
                  var16 = com.aspose.cells.b.a.zc.e(var0, var5 + 2) & '\uffff';

                  for(int var17 = 0; var17 < var16; ++var17) {
                     int var18 = var5 + 6 + var17 * 2;
                     var11 = new int[4];
                     var11[0] = var18 + 2;
                     var20 = com.aspose.cells.b.a.zc.e(var0, var18) & '\uffff';
                     var11[1] = var18 + 2 + var20;
                     var11[2] = var3.b() - (var16 - var17) * 2;
                     com.aspose.cells.b.a.a.ze.a(var4, (Object)var11);
                  }

                  var5 += var19;
                  continue;
               default:
                  var3.a(var0, var5, var13);
                  var5 += var13;
                  continue;
               }
            case 26:
            case 27:
            case 46:
            case 47:
            case 48:
            case 49:
            case 50:
            case 51:
            case 52:
            case 53:
            case 54:
            case 55:
            case 56:
            case 62:
            case 63:
            case 78:
            case 79:
            case 80:
            case 81:
            case 82:
            case 83:
            case 84:
            case 85:
            case 86:
            case 87:
            case 88:
            case 94:
            case 95:
            case 110:
            case 111:
            case 112:
            case 113:
            case 114:
            case 115:
            case 116:
            case 117:
            case 118:
            case 119:
            case 120:
            default:
               var3.a(var0[var5++]);
               break;
            case 28:
            case 29:
               var3.a(var0, var5, 2);
               var5 += 2;
               break;
            case 30:
            case 33:
            case 65:
            case 97:
               var3.a(var0, var5, 3);
               var5 += 3;
               break;
            case 31:
               var3.a(var0, var5, 9);
               var5 += 9;
               break;
            case 32:
            case 64:
            case 96:
               var3.a(var0, var5, 8);
               var5 += 15;
               break;
            case 34:
            case 66:
            case 98:
               var3.a(var0, var5, 4);
               var5 += 4;
               break;
            case 35:
            case 67:
            case 99:
               var3.a(var0, var5, 5);
               var5 += 5;
               break;
            case 36:
            case 68:
            case 100:
               a((ArrayList)var4, var5, 2, var3);
               var7 = com.aspose.cells.b.a.zc.a(var0, var5 + 1);
               var9 = zcew.a(var0, var5 + 5);
               if (var7 <= 65535 && var9 <= 255) {
                  var3.a(var0, var5, 3);
                  var3.a(var0, var5 + 5, 2);
               } else {
                  var3.a((byte)((var0[var5] & 255) + 6));
                  var3.a((int)4);
               }

               var5 += 7;
               break;
            case 37:
            case 69:
            case 101:
               a((ArrayList)var4, var5, 4, var3);
               var7 = com.aspose.cells.b.a.zc.a(var0, var5 + 1);
               var8 = com.aspose.cells.b.a.zc.a(var0, var5 + 5);
               var9 = zcew.a(var0, var5 + 9);
               var10 = zcew.a(var0, var5 + 11);
               if (var7 == 0 && var8 == 1048575) {
                  if (var9 == 0 && var10 == 16383) {
                     var3.a(var0, var5, 3);
                     var3.a(var0, var5 + 5, 2);
                     var3.a(var0, var5 + 9, 3);
                     var3.a((byte)(var0[var5 + 12] & 255 & 192));
                  } else if (var9 <= 255 && var10 <= 255) {
                     var3.a(var0, var5, 3);
                     var3.a(var0, var5 + 5, 2);
                     var3.a(var0, var5 + 9, 4);
                  } else {
                     var3.a((byte)((var0[var5] & 255) + 6));
                     var3.a((int)8);
                  }
               } else if (var9 == 0 && var10 == 16383) {
                  if (var7 <= 65535 && var7 <= 65535) {
                     var3.a(var0, var5, 3);
                     var3.a(var0, var5 + 5, 2);
                     var3.a(var0, var5 + 9, 3);
                     var3.a((byte)(var0[var5 + 12] & 255 & 192));
                  } else {
                     var3.a((byte)((var0[var5] & 255) + 6));
                     var3.a((int)8);
                  }
               } else if (!a(var7, var9, var8, var10)) {
                  var3.a((byte)((var0[var5] & 255) + 6));
                  var3.a((int)8);
               } else {
                  var3.a(var0, var5, 3);
                  var3.a(var0, var5 + 5, 2);
                  var3.a(var0, var5 + 9, 4);
               }

               var5 += 13;
               break;
            case 38:
            case 39:
            case 40:
            case 70:
            case 71:
            case 72:
            case 102:
            case 103:
            case 104:
               var3.a(var0, var5, 5);
               var15 = com.aspose.cells.b.a.zc.e(var0, var5 + 5) & '\uffff';
               var16 = var3.b();
               var3.a((int)2);
               var5 += 7;
               var5 = a(var0, var5, var5 + var15, var3, var4);
               var3.a(var16, com.aspose.cells.b.a.zc.a(var3.b() - var16 - 2), 0, 2);
               break;
            case 41:
            case 73:
            case 105:
               var3.a(var0[var5]);
               var15 = com.aspose.cells.b.a.zc.e(var0, var5 + 1) & '\uffff';
               var16 = var3.b();
               var3.a((int)2);
               var5 += 3;
               var5 = a(var0, var5, var5 + var15, var3, var4);
               var3.a(var16, com.aspose.cells.b.a.zc.a(var3.b() - var16 - 2), 0, 2);
               break;
            case 42:
            case 74:
            case 106:
               a((ArrayList)var4, var5, 2, var3);
               var3.a(var0, var5, 3);
               var3.a(var0, var5 + 5, 2);
               var5 += 7;
               break;
            case 43:
            case 75:
            case 107:
               a((ArrayList)var4, var5, 4, var3);
               var3.a(var0, var5, 3);
               var3.a(var0, var5 + 5, 2);
               var3.a(var0, var5 + 9, 4);
               var5 += 13;
               break;
            case 44:
            case 76:
            case 108:
               a((ArrayList)var4, var5, 2, var3);
               var3.a(var0, var5, 3);
               var3.a(var0[var5 + 5]);
               var3.a((byte)(var0[var5 + 6] & 255 & 192));
               var5 += 7;
               break;
            case 45:
            case 77:
            case 109:
               a((ArrayList)var4, var5, 4, var3);
               var3.a(var0, var5, 3);
               var3.a(var0, var5 + 5, 2);
               var3.a(var0[var5 + 9]);
               var3.a((byte)(var0[var5 + 10] & 255 & 192));
               var3.a(var0[var5 + 11]);
               var3.a((byte)(var0[var5 + 12] & 255 & 192));
               var5 += 13;
               break;
            case 57:
            case 89:
            case 121:
               var3.a(var0, var5, 7);
               var5 += 7;
               break;
            case 58:
            case 90:
            case 122:
               a((ArrayList)var4, var5, 2, var3);
               var7 = com.aspose.cells.b.a.zc.a(var0, var5 + 3);
               var9 = zcew.a(var0, var5 + 7);
               if (var7 <= 65535 && var9 <= 255) {
                  var3.a(var0, var5, 5);
                  var3.a(var0, var5 + 7, 2);
               } else {
                  var3.a((byte)((var0[var5] & 255) + 2));
                  var3.a(var0, var5 + 1, 2);
                  var3.a((int)6);
               }

               var5 += 9;
               break;
            case 59:
            case 91:
            case 123:
               a((ArrayList)var4, var5, 4, var3);
               var7 = com.aspose.cells.b.a.zc.a(var0, var5 + 3);
               var8 = com.aspose.cells.b.a.zc.a(var0, var5 + 7);
               var9 = zcew.a(var0, var5 + 11);
               var10 = zcew.a(var0, var5 + 13);
               if (var7 == 0 && var8 == 1048575) {
                  if (var9 == 0 && var10 == 16383) {
                     var3.a(var0, var5, 5);
                     var3.a(var0, var5 + 7, 2);
                     var3.a(var0, var5 + 11, 3);
                     var3.a((byte)(var0[var5 + 14] & 255 & 192));
                  } else if (var9 <= 255 && var10 <= 255) {
                     var3.a(var0, var5, 5);
                     var3.a(var0, var5 + 7, 2);
                     var3.a(var0, var5 + 11, 4);
                  } else {
                     var3.a((byte)((var0[var5] & 255) + 2));
                     var3.a(var0, var5 + 1, 2);
                     var3.a((int)8);
                  }
               } else if (var9 == 0 && var10 == 16383) {
                  if (var7 <= 65535 && var7 <= 65535) {
                     var3.a(var0, var5, 5);
                     var3.a(var0, var5 + 7, 2);
                     var3.a(var0, var5 + 11, 3);
                     var3.a((byte)(var0[var5 + 14] & 255 & 192));
                  } else {
                     var3.a((byte)((var0[var5] & 255) + 2));
                     var3.a(var0, var5 + 1, 2);
                     var3.a((int)8);
                  }
               } else if (!a(var7, var9, var8, var10)) {
                  var3.a((byte)((var0[var5] & 255) + 2));
                  var3.a(var0, var5 + 1, 2);
                  var3.a((int)8);
               } else {
                  var3.a(var0, var5, 5);
                  var3.a(var0, var5 + 7, 2);
                  var3.a(var0, var5 + 11, 4);
               }

               var5 += 15;
               break;
            case 60:
            case 92:
            case 124:
               a((ArrayList)var4, var5, 2, var3);
               var3.a(var0, var5, 5);
               var3.a(var0, var5 + 7, 2);
               var5 += 9;
               break;
            case 61:
            case 93:
            case 125:
               a((ArrayList)var4, var5, 4, var3);
               var3.a(var0, var5, 5);
               var3.a(var0, var5 + 7, 2);
               var3.a(var0, var5 + 11, 4);
               var5 += 15;
            }
         }

         return var5;
      }
   }

   private static void a(byte[] var0, int var1, int var2, zct var3) {
      int var4 = var1;
      int var5 = var1 + var2;

      while(var4 < var5) {
         int var6 = com.aspose.cells.b.a.zc.a(var0, var4);
         int var7 = com.aspose.cells.b.a.zc.a(var0, var4 + 4);
         var4 += 8;
         var3.a((byte)(var6 - 1));
         var3.a(com.aspose.cells.b.a.zc.a(var7 - 1), 0, 2);

         for(int var8 = 0; var8 < var7; ++var8) {
            for(int var9 = 0; var9 < var6; ++var9) {
               switch(var0[var4]) {
               case 0:
                  var3.a((byte)1);
                  var3.a(var0, var4 + 1, 8);
                  var4 += 9;
                  break;
               case 1:
                  int var10 = com.aspose.cells.b.a.zc.e(var0, var4 + 1) & '\uffff';
                  var3.a((byte)2);
                  if (var10 == 0) {
                     var3.a((int)2);
                  } else {
                     var3.a(var0, var4 + 1, 2);
                     var3.a((byte)1);
                     var3.a(var0, var4 + 3, var10 * 2);
                  }

                  var4 += 3 + var10 * 2;
                  break;
               case 2:
                  var3.a((byte)4);
                  var3.a(var0[var4 + 1]);
                  var3.a((int)7);
                  var4 += 2;
               case 3:
               default:
                  break;
               case 4:
                  var3.a((byte)16);
                  var3.a(var0[var4 + 1]);
                  var3.a((int)7);
                  var4 += 5;
               }
            }
         }
      }

   }
}
